import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
import _createClass from "@babel/runtime/helpers/esm/createClass";
import _assertThisInitialized from "@babel/runtime/helpers/esm/assertThisInitialized";
import _inherits from "@babel/runtime/helpers/esm/inherits";
import _createSuper from "@babel/runtime/helpers/esm/createSuper";
import _applyDecoratedDescriptor from "@babel/runtime/helpers/esm/applyDecoratedDescriptor";
import _isUndefined from "lodash/isUndefined";
import _uniq from "lodash/uniq";
import _uniqBy from "lodash/uniqBy";
import _filter from "lodash/filter";
import _isEmpty from "lodash/isEmpty";
var _excluded = ["subMenus"];

var _dec, _dec2, _dec3, _dec4, _dec5, _dec6, _dec7, _dec8, _dec9, _dec10, _dec11, _dec12, _dec13, _class, _class2;

/**
 * MenuConfig - 菜单配置
 * @date: 2018-7-4
 */
import React from 'react';
import { connect } from 'dva';
import { Bind } from 'lodash-decorators';
import moment from 'moment';
import { Button } from 'antd';
import ExcelExport from 'components/ExcelExport';
import { Content, Header } from 'components/Page';
import { Button as ButtonPermission } from 'components/Permission';
import formatterCollections from 'utils/intl/formatterCollections';
import notification from 'utils/notification';
import intl from 'utils/intl';
import { VERSION_IS_OP } from 'utils/config';
import { getCurrentOrganizationId, filterNullValueObject, getCurrentRole, isTenantRoleLevel, getSession, setSession } from 'utils/utils';
import Editor from "./Editor";
import MenuImport from "./MenuImport";
import MenuExport from "./MenuExport";
import PermissionSet from "./PermissionSet";
import QueryForm from "./Form";
import List from "./List";
import styles from "./index.less?modules";
var commonPrompt = 'cpaas.common';
/**
 * index - 菜单配置
 * @extends {Component} - React.Component
 * @reactProps {Object} [location={}] - 当前路由信息
 * @reactProps {Object} [match={}] - react-router match路由信息
 * @reactProps {!Object} menuConfig - 数据源
 * @reactProps {!Object} loading - 数据加载是否完成
 * @reactProps {Object} form - 表单对象
 * @reactProps {Function} [dispatch=function(e) {return e;}] - redux dispatch方法
 * @return React.element
 */

var MenuConfig = (_dec = connect(function (_ref) {
  var _ref$loading = _ref.loading,
      loading = _ref$loading === void 0 ? {} : _ref$loading,
      menuConfig = _ref.menuConfig;
  return {
    saveDir: loading.effects['menuConfig/saveDir'],
    createDir: loading.effects['menuConfig/createDir'],
    queryPermissions: loading.effects['menuConfig/queryPermissions'],
    queryParentDir: loading.effects['menuConfig/queryParentDir'],
    deleteMenu: loading.effects['menuConfig/deleteMenu'],
    queryTreeList: loading.effects['menuConfig/queryTreeList'],
    setMenuEnable: loading.effects['menuConfig/setMenuEnable'],
    queryPermissionSetTree: loading.effects['menuConfig/queryPermissionSetTree'],
    queryPermissionsById: loading.effects['menuConfig/queryPermissionsById'],
    queryPermissionsByIdAll: loading.effects['menuConfig/queryPermissionsByIdAll'],
    // 已分配的权限
    queryPermissionsByMenuId: loading.effects['menuConfig/queryPermissionsByMenuId'],
    // 可分配的权限
    queryLovsByIdAll: loading.effects['menuConfig/queryLovsByIdAll'],
    // 已分配的Lov
    queryLovByMenuId: loading.effects['menuConfig/queryLovByMenuId'],
    // 可分配的Lov
    assignPermissions: loading.effects['menuConfig/assignPermissions'],
    // 分配权限
    deletePermissions: loading.effects['menuConfig/deletePermissions'],
    // 删除权限
    setPermissionLoading: loading.effects['menuConfig/setPermissionSetEnable'],
    // 启用/禁用 权限集
    customMenuLoading: loading.effects['menuConfig/queryOrganizationCustomMenu'],
    // 客户化菜单
    exportCustomMenuLoading: loading.effects['menuConfig/exportCustomMenu'],
    // 客户化菜单导出
    // refreshRoutePermissionSetLoading: loading.effects['menuConfig/refreshRoutePermissionSet'], // 刷新 UI组件权限集
    queryCopyMenuListLoading: loading.effects['menuConfig/queryCopyMenuList'],
    // 复制菜单列表
    copyCreateLoading: loading.effects['menuConfig/copyMenu'],
    // 复制并创建菜单
    menuConfig: menuConfig,
    currentRoleCode: getCurrentRole().code,
    isSiteFlag: !isTenantRoleLevel()
  };
}), _dec2 = formatterCollections({
  code: ['ciam.menuConfig', 'ciam.menu']
}), _dec3 = Bind(), _dec4 = Bind(), _dec5 = Bind(), _dec6 = Bind(), _dec7 = Bind(), _dec8 = Bind(), _dec9 = Bind(), _dec10 = Bind(), _dec11 = Bind(), _dec12 = Bind(), _dec13 = Bind(), _dec(_class = _dec2(_class = (_class2 = /*#__PURE__*/function (_React$Component) {
  _inherits(MenuConfig, _React$Component);

  var _super = _createSuper(MenuConfig);

  function MenuConfig(props) {
    var _this;

    _classCallCheck(this, MenuConfig);

    _this = _super.call(this, props);
    _this.state = {
      recordCreateFlag: false,
      // 标识是否是行上新建
      editorVisible: false,
      // TODO:
      // menuImportVisible: false,
      menuExportVisible: false,
      exportSelectedRowKeys: [],
      exportSelectedRows: [],
      permissionSetVisible: false,
      currentRowData: {},
      expandedRowKeys: getSession('ciam-menuConfig-expandedRowKeys') || [],
      processingDeleteRow: null,
      processingEnableRow: null,
      copyFlag: false // 是否为复制新建

    };
    _this.fetchList = _this.fetchList.bind(_assertThisInitialized(_this)); // this.closeMenuImportDrawer = this.closeMenuImportDrawer.bind(this);

    return _this;
  }

  _createClass(MenuConfig, [{
    key: "componentDidMount",
    value:
    /**
     * componentDidMount 生命周期函数
     * render后请求页面数据
     */
    function componentDidMount() {
      this.fetchList({
        level: 'site'
      });
      this.fetchAssignLevelCode();
      this.handleQueryLabel();
      this.fetchSearchLabels();
      var lovCodes = {
        menuPrefix: 'CIAM.MENU_PREFIX',
        // 目录编码前缀
        menuType: 'CIAM.MENU_TYPE',
        // 菜单类型
        controllerType: 'CIAM.CONTROLLER_TYPE' // 权限集控制类型

      }; // 初始化 值集

      this.props.dispatch({
        type: 'menuConfig/init',
        payload: {
          lovCodes: lovCodes
        }
      });
    }
    /**
     * componentWillUnmount  生命周期函数
     * 组件消失时，清除session缓存
     */

  }, {
    key: "componentWillUnmount",
    value: function componentWillUnmount() {
      window.sessionStorage.removeItem('ciam-menuConfig-expandedRowKeys');
    }
    /**
     * @function getRowKeys - 获取查询到数据的parentId
     * @param {!array} collections - 查询获取的数据
     */

  }, {
    key: "getRowKeys",
    value: function getRowKeys() {
      var _this2 = this;

      var collections = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
      var param = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
      var rowKeys = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
      var name = param.name,
          quickIndex = param.quickIndex,
          parentName = param.parentName;
      var arr = rowKeys;
      var renderTree = collections.map(function (item) {
        var temp = item;

        if ((!_isEmpty(name) && temp.name.includes(name) || !_isEmpty(temp.quickIndex) && !_isEmpty(quickIndex) && temp.quickIndex.includes(quickIndex) || !_isEmpty(temp.parentName) && !_isEmpty(parentName) && temp.parentName.includes(parentName)) && !arr.includes(temp.parentId)) {
          arr.push(temp.parentId);
        }

        if (temp.subMenus) {
          temp.subMenus = _toConsumableArray(_this2.getRowKeys(temp.subMenus || [], param, arr).renderTree);
        }

        return temp;
      });
      var renderTree2 = collections.map(function (item) {
        var temp = item;

        if (rowKeys.includes(temp.id) && _isEmpty(temp.parentId) && !arr.includes(temp.parentId)) {
          arr.push(temp.parentId);
        }

        if (temp.subMenus) {
          temp.subMenus = _toConsumableArray(_this2.getRowKeys(temp.subMenus || [], param, arr).renderTree2);
        }

        return temp;
      });
      return {
        renderTree: renderTree,
        renderTree2: renderTree2,
        param: param,
        rowKeys: rowKeys
      };
    }
    /**
     * 查询搜索字段 标签 数据
     */

  }, {
    key: "fetchSearchLabels",
    value: function fetchSearchLabels() {
      var dispatch = this.props.dispatch;
      dispatch({
        type: 'menuConfig/querySearchLabels',
        payload: {
          type: 'MENU'
        }
      });
    }
    /**
     * fetchList - 查询列表数据
     * @param {object} [params = {}] - 查询参数
     * @param {string} params.name - 目录/菜单名
     * @param {string} params.parentName - 上级目录
     */

  }, {
    key: "fetchList",
    value: function fetchList() {
      var _this3 = this;

      var params = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
      var flag = arguments.length > 1 ? arguments[1] : undefined;
      var dispatch = this.props.dispatch;
      dispatch({
        type: 'menuConfig/queryTreeList',
        params: params
      }).then(function (res) {
        if (res) {
          var _this3$getRowKeys = _this3.getRowKeys(res, params),
              rowKeys = _this3$getRowKeys.rowKeys;

          if (flag) {
            _this3.setState({
              expandedRowKeys: rowKeys
            });

            window.sessionStorage.removeItem('ciam-menuConfig-expandedRowKeys');
          } else {
            var expandedRowKeys = _this3.state.expandedRowKeys;

            var arr = _uniq(rowKeys.concat(expandedRowKeys));

            _this3.setState({
              expandedRowKeys: arr
            });
          }
        }
      });
    }
    /**
     * fetchAssignLevelCode - 查询层级<CIAM.RESOURCE_LEVEL>code
     * @return {Array}
     */

  }, {
    key: "fetchAssignLevelCode",
    value: function fetchAssignLevelCode() {
      var dispatch = this.props.dispatch;
      return dispatch({
        type: 'menuConfig/queryCode',
        payload: {
          lovCode: 'CIAM.RESOURCE_LEVEL'
        }
      });
    }
    /**
     * fetchDir - 查询上级目录
     * @param {object} [params = {}] - 查询参数
     * @param {!string} params.level - 层级
     * @param {Function} cb - 获取成功的回调函数
     */

  }, {
    key: "fetchDir",
    value: function fetchDir(params) {
      var cb = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : function (e) {
        return e;
      };
      var dispatch = this.props.dispatch;
      dispatch({
        type: 'menuConfig/queryParentDir',
        params: params
      }).then(function (res) {
        if (res) {
          cb(res);
        }
      });
    }
    /**
     * fetchMenuPermissions - 查询菜单权限
     * @param {object} [params = {}] - 查询参数
     * @param {!string} params.level - 层级
     * @param {!number} [params.size=10] - 分页数目
     * @param {!number} [params.page=0] - 当前页
     * @return {Array}
     */

  }, {
    key: "fetchMenuPermissions",
    value: function fetchMenuPermissions(params) {
      var dispatch = this.props.dispatch;
      var currentRowData = this.state.currentRowData;
      return dispatch({
        type: 'menuConfig/queryPermissions',
        params: _objectSpread(_objectSpread({}, params), {}, {
          excludeHasAssignedMenuId: currentRowData.id
        })
      });
    }
    /**
     * fetchPermissionSetTree - 查询菜单权限集树
     * @param {!number} menuId - 菜单ID
     * @param {object} [params = {}] - 查询参数
     * @return {Array}
     */

  }, {
    key: "fetchPermissionSetTree",
    value: function fetchPermissionSetTree(menuId, params) {
      var dispatch = this.props.dispatch;
      return dispatch({
        type: 'menuConfig/queryPermissionSetTree',
        menuId: menuId,
        params: params
      });
    } // 查询权限集下可分配的所有权限

  }, {
    key: "fetchPermissionsByMenuId",
    value: function fetchPermissionsByMenuId(menuId, params) {
      var dispatch = this.props.dispatch;
      return dispatch({
        type: 'menuConfig/queryPermissionsByMenuId',
        menuId: menuId,
        params: params
      });
    } // 可分配的Lov

  }, {
    key: "fetchLovByMenuId",
    value: function fetchLovByMenuId(menuId, params) {
      var dispatch = this.props.dispatch;
      return dispatch({
        type: 'menuConfig/queryLovByMenuId',
        menuId: menuId,
        params: params
      });
    }
  }, {
    key: "assignPermissions",
    value: function assignPermissions() {
      var params = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
      var dispatch = this.props.dispatch;
      return dispatch({
        type: 'menuConfig/assignPermissions',
        payload: _objectSpread({}, params)
      });
    }
  }, {
    key: "deletePermissions",
    value: function deletePermissions() {
      var params = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
      var dispatch = this.props.dispatch;
      return dispatch({
        type: 'menuConfig/deletePermissions',
        payload: _objectSpread({}, params)
      });
    }
  }, {
    key: "fetchPermissionsById",
    value: function fetchPermissionsById(permissionSetId, params) {
      var dispatch = this.props.dispatch;
      return dispatch({
        type: 'menuConfig/queryPermissionsById',
        permissionSetId: permissionSetId,
        params: params
      });
    } // 查询权限集下已分配的权限

  }, {
    key: "fetchPermissionsByIdAll",
    value: function fetchPermissionsByIdAll(permissionSetId, params) {
      var dispatch = this.props.dispatch;
      return dispatch({
        type: 'menuConfig/queryPermissionsByIdAll',
        permissionSetId: permissionSetId,
        params: params
      });
    } // 查询权限集下已分配的Lov

  }, {
    key: "fetchLovsByIdAll",
    value: function fetchLovsByIdAll(permissionSetId, params) {
      var dispatch = this.props.dispatch;
      return dispatch({
        type: 'menuConfig/queryLovsByIdAll',
        permissionSetId: permissionSetId,
        params: params
      });
    }
    /**
     * create - 创建菜单/打开编辑右侧弹窗
     */

  }, {
    key: "create",
    value: function create() {
      var record = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
      var recordCreateFlag = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
      var id = record.id,
          code = record.code,
          level = record.level;
      var initData = id !== undefined ? {
        level: level,
        code: code,
        parentId: id,
        parentName: record.name
      } : {};
      this.setState({
        recordCreateFlag: recordCreateFlag,
        editorVisible: true,
        currentRowData: initData
      });
    }
    /**
     * 复制菜单
     * @param {object} record - 表格行数据
     */

  }, {
    key: "copy",
    value: function copy(record) {
      var id = record.id,
          code = record.code,
          level = record.level,
          type = record.type,
          _record$levelPath = record.levelPath,
          levelPath = _record$levelPath === void 0 ? '' : _record$levelPath,
          description = record.description,
          icon = record.icon,
          quickIndex = record.quickIndex,
          route = record.route,
          sort = record.sort,
          name = record.name,
          parentName = record.parentName,
          virtualFlag = record.virtualFlag,
          parentId = record.parentId;
      var initData = {
        currentId: id,
        level: level,
        levelPath: levelPath,
        code: code,
        parentId: parentId,
        parentName: parentName,
        type: type,
        description: description,
        icon: icon,
        quickIndex: quickIndex,
        route: route,
        sort: sort,
        name: name,
        virtualFlag: virtualFlag
      };
      this.setState({
        copyFlag: true,
        recordCreateFlag: true,
        editorVisible: true,
        currentRowData: initData
      });
    }
    /**
     * 获取当前节点及其子节点
     */

  }, {
    key: "fetchCopyMenuList",
    value: function fetchCopyMenuList(params) {
      var dispatch = this.props.dispatch;
      return dispatch({
        type: 'menuConfig/queryCopyMenuList',
        params: params
      });
    }
    /**
     * createDir - 创建目录
     * @param {!object} [params = {}] - form数据
     * @param {Function} cb - 获取成功的回调函数
     */

  }, {
    key: "createDir",
    value: function createDir(params) {
      var _this4 = this;

      var cb = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : function (e) {
        return e;
      };
      var dispatch = this.props.dispatch;

      var _ref2 = this.search || {},
          _ref2$getFieldsValue = _ref2.getFieldsValue,
          getFieldsValue = _ref2$getFieldsValue === void 0 ? function (e) {
        return e;
      } : _ref2$getFieldsValue;

      dispatch({
        type: 'menuConfig/createDir',
        params: params
      }).then(function (res) {
        if (res) {
          notification.success();
          cb();

          _this4.fetchList(getFieldsValue());
        }
      });
    }
    /**
     * createPermissionSet - 新建权限集
     * @param {!object} [params = {}] - form数据
     * @param {Function} cb - 获取成功的回调函数
     */

  }, {
    key: "createPermissionSet",
    value: function createPermissionSet(params) {
      var cb = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : function (e) {
        return e;
      };
      var dispatch = this.props.dispatch;
      dispatch({
        type: 'menuConfig/createDir',
        params: params
      }).then(function (res) {
        if (res) {
          notification.success();
          cb();
        }
      });
    }
    /**
     * handleCopyCreate - 复制并创建菜单
     * @param {!object} [payload = {}] - form数据
     * @param {Function} cb - 获取成功的回调函数
     */

  }, {
    key: "handleCopyCreate",
    value: function handleCopyCreate(payload) {
      var _this5 = this;

      var cb = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : function (e) {
        return e;
      };
      var dispatch = this.props.dispatch;
      var level = this.state.currentRowData.level;

      var _ref3 = this.search || {},
          _ref3$getFieldsValue = _ref3.getFieldsValue,
          getFieldsValue = _ref3$getFieldsValue === void 0 ? function (e) {
        return e;
      } : _ref3$getFieldsValue;

      dispatch({
        type: 'menuConfig/copyMenu',
        payload: {
          data: payload,
          level: level.toUpperCase()
        }
      }).then(function (res) {
        if (res) {
          notification.success();
          cb();

          _this5.fetchList(getFieldsValue());
        }
      });
    }
    /**
     * handleQueryLabel - 查询label列表
     * @param {!object} [payload = {}] - form数据
     * @param {Function} cb - 获取成功的回调函数
     */

  }, {
    key: "handleQueryLabel",
    value: function handleQueryLabel() {
      var dispatch = this.props.dispatch;
      dispatch({
        type: 'menuConfig/queryLabelList'
      });
    }
    /**
     * handleQueryLabel - 查询label列表
     * @param {!object} [payload = {}] - form数据
     * @param {Function} cb - 获取成功的回调函数
     */

  }, {
    key: "handleQueryMenuLabel",
    value: function handleQueryMenuLabel(payload) {
      var dispatch = this.props.dispatch;
      return dispatch({
        type: 'menuConfig/queryMenuLabel',
        payload: payload
      });
    }
    /**
     * saveDir - 保存目录
     * @param {!object} [params = {}] - form数据
     * @param {Function} cb - 获取成功的回调函数
     */

  }, {
    key: "saveDir",
    value: function saveDir(params) {
      var _this6 = this;

      var cb = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : function (e) {
        return e;
      };
      var dispatch = this.props.dispatch;

      var _ref4 = this.search || {},
          _ref4$getFieldsValue = _ref4.getFieldsValue,
          getFieldsValue = _ref4$getFieldsValue === void 0 ? function (e) {
        return e;
      } : _ref4$getFieldsValue;

      dispatch({
        type: 'menuConfig/saveDir',
        params: params
      }).then(function (res) {
        if (res) {
          notification.success();
          cb();

          _this6.fetchList(getFieldsValue());
        }
      });
    }
    /**
     * savePermissionSet - 更新权限集
     * @param {!object} [params = {}] - form数据
     * @param {Function} cb - 获取成功的回调函数
     */

  }, {
    key: "savePermissionSet",
    value: function savePermissionSet(params) {
      var cb = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : function (e) {
        return e;
      };
      var dispatch = this.props.dispatch;
      dispatch({
        type: 'menuConfig/saveDir',
        params: params
      }).then(function (res) {
        if (res) {
          notification.success();
          cb();
        }
      });
    }
    /**
     * edit - 编辑菜单/打开编辑右侧弹窗
     * @param {!object} [record = {}] - 当前行数据
     */

  }, {
    key: "edit",
    value: function edit(record) {
      this.setState({
        editorVisible: true,
        recordCreateFlag: false,
        currentRowData: record
      });
    }
    /**
     * delete - 编辑菜单/打开编辑右侧弹窗
     * @param {!object} [record = {}] - 当前行数据
     */

  }, {
    key: "delete",
    value: function _delete(record) {
      var _this7 = this;

      var dispatch = this.props.dispatch;

      var _ref5 = this.search || {},
          _ref5$getFieldsValue = _ref5.getFieldsValue,
          getFieldsValue = _ref5$getFieldsValue === void 0 ? function (e) {
        return e;
      } : _ref5$getFieldsValue;

      this.setState({
        processingDeleteRow: record.id
      });
      dispatch({
        type: 'menuConfig/deleteMenu',
        id: record.id
      }).then(function (res) {
        if (res && res.failed) {
          notification.error({
            description: res.message
          });
        } else {
          notification.success();

          _this7.fetchList(getFieldsValue());
        }

        _this7.setState({
          processingDeleteRow: null
        });
      });
    }
  }, {
    key: "setPermissionSetEnable",
    value: function setPermissionSetEnable(record, paramType) {
      var cb = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : function (e) {
        return e;
      };
      var dispatch = this.props.dispatch;
      dispatch({
        type: 'menuConfig/setPermissionSetEnable',
        payload: {
          id: record.id,
          _token: record._token,
          paramType: paramType
        }
      }).then(function (res) {
        if (res) {
          notification.success();
          cb();
        }
      });
    }
  }, {
    key: "setMenuEnable",
    value: function setMenuEnable(record, paramType) {
      var _this8 = this;

      var dispatch = this.props.dispatch;

      var _ref6 = this.search || {},
          _ref6$getFieldsValue = _ref6.getFieldsValue,
          getFieldsValue = _ref6$getFieldsValue === void 0 ? function (e) {
        return e;
      } : _ref6$getFieldsValue;

      this.setState({
        processingEnableRow: record.id
      });
      dispatch({
        type: 'menuConfig/setMenuEnable',
        payload: {
          id: record.id,
          _token: record._token,
          paramType: paramType
        }
      }).then(function (res) {
        if (res) {
          notification.success();

          _this8.fetchList(getFieldsValue());
        }

        _this8.setState({
          processingEnableRow: record.id
        });
      });
    }
    /**
     * closeEditor - 关闭编辑右侧弹窗
     */

  }, {
    key: "closeEditor",
    value: function closeEditor() {
      this.setState({
        editorVisible: false,
        currentRowData: {},
        copyFlag: false
      });
    }
    /**
     * checkMenuDirExists - 校验目录编码是否存在
     * @param {!object} [params = {}] - 条件
     * @param {!string} params.code - 编码
     * @param {!string} params.level - 层级
     * @param {!number} params.tenantId - 租户编码
     * @param {!string} params.type - 类别
     * @return {null|object}
     */

  }, {
    key: "checkMenuDirExists",
    value: function checkMenuDirExists(params) {
      var dispatch = this.props.dispatch;
      return dispatch({
        type: 'menuConfig/checkMenuDirExists',
        params: params
      });
    } // TODO:
    // /**
    //  * openMenuImportDrawer - 打开菜单导入抽屉
    //  */
    // openMenuImportDrawer() {
    //   this.setState({
    //     menuImportVisible: true,
    //   });
    // }
    // TODO:
    // /**
    //  * closeMenuImportDrawer - 关闭菜单导入抽屉
    //  */
    // closeMenuImportDrawer() {
    //   this.setState({
    //     menuImportVisible: false,
    //   });
    // }

    /**
     * 查询客户化菜单
     */

  }, {
    key: "fetchCustomMenu",
    value: function fetchCustomMenu() {
      var dispatch = this.props.dispatch;
      dispatch({
        type: 'menuConfig/queryOrganizationCustomMenu',
        payload: {}
      });
    }
    /**
     * 打开菜单导出抽屉
     */

  }, {
    key: "openMenuExportDrawer",
    value: function openMenuExportDrawer() {
      this.fetchCustomMenu();
      this.setState({
        menuExportVisible: true
      });
    }
    /**
     * 关闭菜单导出抽屉
     */

  }, {
    key: "closeMenuExportDrawer",
    value: function closeMenuExportDrawer() {
      var dispatch = this.props.dispatch;
      dispatch({
        type: 'menuConfig/updateStateReducer',
        payload: {
          customMenu: {
            list: []
          }
        }
      });
      this.setState({
        menuExportVisible: false,
        exportSelectedRowKeys: [],
        exportSelectedRows: []
      });
    }
    /**
     * 选中或取消选中导出的菜单
     * @param {object} record - 当前行数据
     * @param {boolean} selected - 是否选中
     */

  }, {
    key: "handleExportRowSelect",
    value: function handleExportRowSelect(record, selected) {
      var _this$state = this.state,
          exportSelectedRowKeys = _this$state.exportSelectedRowKeys,
          exportSelectedRows = _this$state.exportSelectedRows; // 目前只能通过rootNode为true,或parentId=0来判断为根节点。只有根节点为类型为根目录才可以勾选

      if (selected && !record.rootNode) {
        // 子节点被勾选时，其父节点必须已经被勾选，否则会造成断层
        var targetParent = exportSelectedRowKeys.includes(record.parentId);
        if (!targetParent) return;
      }

      var setIdList = [];
      var setRowList = [];
      var nextRows = [];

      var getSubSetIdList = function getSubSetIdList() {
        var collections = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
        collections.forEach(function (n) {
          setIdList.push(n.id);

          if (selected) {
            setRowList.push(n);
          }

          if (!_isEmpty(n.subMenus)) {
            getSubSetIdList(n.subMenus);
          }
        });
      };

      if (!_isEmpty(record.subMenus)) {
        getSubSetIdList(record.subMenus);
      }

      setIdList.push(record.id);

      var filteredRowKeys = _filter(exportSelectedRowKeys, function (item) {
        return !setIdList.includes(item);
      });

      if (selected) {
        setRowList.push(record);
        nextRows = _uniqBy(exportSelectedRows.concat(setRowList), 'id');
      } else {
        nextRows = _filter(exportSelectedRows, function (item) {
          return filteredRowKeys.includes(item.id);
        });
      } // exportSelectedRows中存储的是打平的树形数据 不含subMenus


      var nextExportSelectedRows = nextRows.map(function (row) {
        var nextRow = _objectSpread({}, row);

        var subMenus = nextRow.subMenus,
            rest = _objectWithoutProperties(nextRow, _excluded);

        var newValue = _objectSpread({}, rest);

        return newValue;
      });
      this.setState({
        exportSelectedRowKeys: selected ? exportSelectedRowKeys.concat(setIdList) : filteredRowKeys,
        exportSelectedRows: nextExportSelectedRows
      });
    }
    /**
     * 导出客户化菜单
     */

  }, {
    key: "handleExport",
    value: function handleExport() {
      var dispatch = this.props.dispatch;
      var exportSelectedRows = this.state.exportSelectedRows;
      var timeStamp = moment().format('YYYYMMDDhhmmss'); // 非根节点勾选时，父节点必须勾选

      dispatch({
        type: 'menuConfig/exportCustomMenu',
        payload: exportSelectedRows
      }).then(function (res) {
        if (res) {
          var bl = new Blob([res], {
            type: 'application/json'
          });
          var fileName = intl.get('ciam.menuConfig.view.message.title.customMenu', {
            name: timeStamp
          }).d("\u5BA2\u6237\u5316\u83DC\u5355_".concat(timeStamp));
          var link = document.createElement('a');
          link.href = window.URL.createObjectURL(bl);
          link.download = fileName;
          link.click();
        }
      });
    }
    /**
     * 导入客户化菜单后刷新页面
     */

  }, {
    key: "refreshList",
    value: function refreshList() {
      var _ref7 = this.search || {},
          _ref7$getFieldsValue = _ref7.getFieldsValue,
          getFieldsValue = _ref7$getFieldsValue === void 0 ? function (e) {
        return e;
      } : _ref7$getFieldsValue;

      this.fetchList(getFieldsValue());
    }
    /**
     * expandAll - 全部展开
     */

  }, {
    key: "expandAll",
    value: function expandAll() {
      var menuConfig = this.props.menuConfig;
      var list = menuConfig.list;
      setSession('ciam-menuConfig-expandedRowKeys', list.rowKeys);
      this.setState({
        expandedRowKeys: list.rowKeys
      });
    }
    /**
     * collapseAll - 全部收起
     */

  }, {
    key: "collapseAll",
    value: function collapseAll() {
      setSession('ciam-menuConfig-expandedRowKeys', []);
      this.setState({
        expandedRowKeys: []
      });
    }
    /**
     * 点击图标时触发
     * @param { boolean } expanded
     * @param { object } record
     */

  }, {
    key: "expandClick",
    value: function expandClick(expanded, record) {
      var expandedRowKeys = this.state.expandedRowKeys;
      var id = record.id;
      expandedRowKeys = expanded ? expandedRowKeys.concat(id) : expandedRowKeys.filter(function (item) {
        return item !== id;
      });
      setSession('ciam-menuConfig-expandedRowKeys', expandedRowKeys);
      this.setState({
        expandedRowKeys: expandedRowKeys
      });
    }
  }, {
    key: "openPermissionSetDrawer",
    value: function openPermissionSetDrawer(record) {
      this.setState({
        currentRowData: record,
        permissionSetVisible: true
      });
    }
  }, {
    key: "closePermissionSetDrawer",
    value: function closePermissionSetDrawer() {
      this.setState({
        currentRowData: {},
        permissionSetVisible: false
      });
    }
    /**
     * 获取form数据
     */

  }, {
    key: "handleGetFormValue",
    value: function handleGetFormValue() {
      var formValue = _isUndefined(this.search) ? {} : this.search.getFieldsValue();
      var filterValues = filterNullValueObject(formValue);
      return filterValues;
    }
  }, {
    key: "render",
    value: function render() {
      var _this9 = this;

      var _this$props = this.props,
          isSiteFlag = _this$props.isSiteFlag,
          _this$props$menuConfi = _this$props.menuConfig,
          menuConfig = _this$props$menuConfi === void 0 ? {} : _this$props$menuConfi,
          currentRoleCode = _this$props.currentRoleCode,
          saveDir = _this$props.saveDir,
          createDir = _this$props.createDir,
          queryPermissions = _this$props.queryPermissions,
          queryParentDir = _this$props.queryParentDir,
          deleteMenu = _this$props.deleteMenu,
          queryTreeList = _this$props.queryTreeList,
          setMenuEnable = _this$props.setMenuEnable,
          queryPermissionSetTree = _this$props.queryPermissionSetTree,
          queryPermissionsById = _this$props.queryPermissionsById,
          queryPermissionsByIdAll = _this$props.queryPermissionsByIdAll,
          queryPermissionsByMenuId = _this$props.queryPermissionsByMenuId,
          queryLovsByIdAll = _this$props.queryLovsByIdAll,
          queryLovByMenuId = _this$props.queryLovByMenuId,
          assignPermissions = _this$props.assignPermissions,
          deletePermissions = _this$props.deletePermissions,
          setPermissionLoading = _this$props.setPermissionLoading,
          customMenuLoading = _this$props.customMenuLoading,
          exportCustomMenuLoading = _this$props.exportCustomMenuLoading,
          queryCopyMenuListLoading = _this$props.queryCopyMenuListLoading,
          copyCreateLoading = _this$props.copyCreateLoading,
          path = _this$props.match.path;
      var _this$state2 = this.state,
          recordCreateFlag = _this$state2.recordCreateFlag,
          editorVisible = _this$state2.editorVisible,
          currentRowData = _this$state2.currentRowData,
          menuExportVisible = _this$state2.menuExportVisible,
          expandedRowKeys = _this$state2.expandedRowKeys,
          processingDeleteRow = _this$state2.processingDeleteRow,
          processingEnableRow = _this$state2.processingEnableRow,
          permissionSetVisible = _this$state2.permissionSetVisible,
          exportSelectedRowKeys = _this$state2.exportSelectedRowKeys,
          copyFlag = _this$state2.copyFlag;
      var _menuConfig$code = menuConfig.code,
          code = _menuConfig$code === void 0 ? {} : _menuConfig$code,
          list = menuConfig.list,
          _menuConfig$searchLab = menuConfig.searchLabels,
          searchLabels = _menuConfig$searchLab === void 0 ? [] : _menuConfig$searchLab,
          _menuConfig$menuPrefi = menuConfig.menuPrefixList,
          menuPrefixList = _menuConfig$menuPrefi === void 0 ? [] : _menuConfig$menuPrefi,
          _menuConfig$menuTypeL = menuConfig.menuTypeList,
          menuTypeList = _menuConfig$menuTypeL === void 0 ? [] : _menuConfig$menuTypeL,
          _menuConfig$controlle = menuConfig.controllerType,
          controllerType = _menuConfig$controlle === void 0 ? [] : _menuConfig$controlle,
          _menuConfig$customMen = menuConfig.customMenu,
          customMenu = _menuConfig$customMen === void 0 ? {} : _menuConfig$customMen,
          _menuConfig$siteLabel = menuConfig.siteLabelList,
          siteLabelList = _menuConfig$siteLabel === void 0 ? [] : _menuConfig$siteLabel,
          _menuConfig$tenantLab = menuConfig.tenantLabelList,
          tenantLabelList = _menuConfig$tenantLab === void 0 ? [] : _menuConfig$tenantLab;
      var effects = {
        saveDir: saveDir,
        createDir: createDir,
        queryPermissions: queryPermissions,
        queryParentDir: queryParentDir,
        deleteMenu: deleteMenu,
        queryTreeList: queryTreeList,
        setMenuEnable: setMenuEnable,
        queryPermissionSetTree: queryPermissionSetTree,
        queryPermissionsById: queryPermissionsById,
        queryPermissionsByIdAll: queryPermissionsByIdAll,
        queryPermissionsByMenuId: queryPermissionsByMenuId,
        queryLovsByIdAll: queryLovsByIdAll,
        queryLovByMenuId: queryLovByMenuId,
        assignPermissions: assignPermissions,
        deletePermissions: deletePermissions,
        setPermissionLoading: setPermissionLoading,
        // refreshRoutePermissionSetLoading,
        queryCopyMenuListLoading: queryCopyMenuListLoading,
        copyCreateLoading: copyCreateLoading
      };
      var organizationId = getCurrentOrganizationId();
      var formProps = {
        ref: function ref(_ref8) {
          _this9.search = _ref8;
        },
        handleQueryList: this.fetchList.bind(this),
        levelCode: code['CIAM.RESOURCE_LEVEL'],
        searchLabels: searchLabels
      };
      var editorProps = {
        path: path,
        recordCreateFlag: recordCreateFlag,
        isSiteFlag: isSiteFlag,
        copyFlag: copyFlag,
        menuPrefixList: menuPrefixList,
        menuTypeList: menuTypeList,
        visible: editorVisible,
        handleCheckMenuDirExists: this.checkMenuDirExists.bind(this),
        levelCode: code['CIAM.RESOURCE_LEVEL'],
        onCancel: this.closeEditor.bind(this),
        dataSource: currentRowData,
        fetchCopyMenuList: this.fetchCopyMenuList.bind(this),
        handleQueryDir: this.fetchDir.bind(this),
        handleSave: this.saveDir.bind(this),
        handleCreate: this.createDir.bind(this),
        handleQueryPermissions: this.fetchMenuPermissions.bind(this),
        handleQueryPermissionsBySet: this.fetchPermissionsById.bind(this),
        handleCopyCreate: this.handleCopyCreate.bind(this),
        queryLabel: this.handleQueryMenuLabel.bind(this),
        siteLabelList: siteLabelList,
        tenantLabelList: tenantLabelList,
        processing: {
          save: effects.saveDir,
          create: effects.createDir,
          queryPermissions: effects.queryPermissions,
          queryDir: effects.queryParentDir,
          queryCopyMenu: effects.queryCopyMenuListLoading,
          copyCreate: effects.copyCreateLoading
        }
      };
      var exportRowSelection = {
        selectedRowKeys: exportSelectedRowKeys,
        onSelect: this.handleExportRowSelect
      };
      var menuExportProps = {
        visible: menuExportVisible,
        loading: customMenuLoading,
        confirmLoading: exportCustomMenuLoading,
        dataSource: customMenu.list || [],
        menuTypeList: menuTypeList,
        rowSelection: exportRowSelection,
        onFecthCustomMenu: this.fetchCustomMenu,
        onCancel: this.closeMenuExportDrawer.bind(this),
        onExport: this.handleExport
      };
      var menuImportProps = {
        path: path,
        onReload: this.refreshList
      };
      var listProps = {
        path: path,
        menuTypeList: menuTypeList,
        levelCode: code['CIAM.RESOURCE_LEVEL'],
        dataSource: list.dataSource,
        handleEdit: this.edit.bind(this),
        handleDelete: this.delete.bind(this),
        handleEditPermissionSet: this.openPermissionSetDrawer.bind(this),
        handleEnable: this.setMenuEnable.bind(this),
        expandClick: this.expandClick,
        processing: {
          delete: effects.deleteMenu,
          query: effects.queryTreeList,
          setEnable: effects.setMenuEnable
        },
        expandedRowKeys: expandedRowKeys,
        uncontrolled: true,
        processingDeleteRow: processingDeleteRow,
        processingEnableRow: processingEnableRow,
        organizationId: organizationId,
        onCreate: this.create,
        onCopy: this.copy
      };
      var permissionSetProps = {
        path: path,
        controllerType: controllerType,
        currentRoleCode: currentRoleCode,
        visible: permissionSetVisible,
        menuDataSource: currentRowData,
        close: this.closePermissionSetDrawer.bind(this),
        handleQueryList: this.fetchPermissionSetTree.bind(this),
        handleQueryPermissionsBySet: this.fetchPermissionsByIdAll.bind(this),
        // 查询权限集下已分配的权限
        handleQueryPermissions: this.fetchPermissionsByMenuId.bind(this),
        // 查询权限集下可分配的所有权限
        handleQueryLovsBySet: this.fetchLovsByIdAll.bind(this),
        // 查询权限集下已分配的Lov
        handleQueryLovs: this.fetchLovByMenuId.bind(this),
        // 查询权限集下可分配的所有Lov
        onAssignPermissions: this.assignPermissions.bind(this),
        onDeletePermissions: this.deletePermissions.bind(this),
        handleSave: this.savePermissionSet.bind(this),
        handleCreate: this.createPermissionSet.bind(this),
        handleEnable: this.setPermissionSetEnable.bind(this),
        // refreshRoutePermissionSetLoading: effects.refreshRoutePermissionSetLoading,
        processing: {
          query: effects.queryPermissionSetTree,
          save: effects.saveDir,
          create: effects.createDir,
          queryPermissionsById: effects.queryPermissionsById,
          queryPermissionsByIdAll: effects.queryPermissionsByIdAll,
          // 已分配的权限
          queryPermissionsByMenuId: effects.queryPermissionsByMenuId,
          // 可分配的权限
          queryLovsByIdAll: effects.queryLovsByIdAll,
          // 已分配的Lov
          queryLovByMenuId: effects.queryLovByMenuId,
          // 可分配的Lov
          assignPermissions: effects.assignPermissions,
          // 分配权限
          deletePermissions: effects.deletePermissions,
          // 删除权限
          setPermissionLoading: effects.setPermissionLoading // 启用/禁用 权限集

        } // save:

      };
      return /*#__PURE__*/React.createElement("div", {
        className: styles['ciam-menu-config']
      }, /*#__PURE__*/React.createElement(Header, {
        title: intl.get('ciam.menu.view.message.title').d('菜单配置')
      }, /*#__PURE__*/React.createElement(ButtonPermission, {
        permissionList: [{
          code: "".concat(path, ".button.create"),
          type: 'button',
          meaning: '菜单配置-新建'
        }],
        type: "primary",
        icon: "plus",
        onClick: function onClick() {
          return _this9.create({}, false);
        }
      }, intl.get('cpaas.common.button.create').d('新建')), /*#__PURE__*/React.createElement(Button, {
        icon: "up",
        onClick: this.collapseAll.bind(this),
        disabled: effects.queryTreeList
      }, intl.get("".concat(commonPrompt, ".button.collapseAll")).d('全部收起')), /*#__PURE__*/React.createElement(Button, {
        icon: "down",
        onClick: this.expandAll.bind(this),
        disabled: effects.queryTreeList
      }, intl.get("".concat(commonPrompt, ".button.expandAll")).d('全部展开')), !isSiteFlag && !VERSION_IS_OP && /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(MenuImport, menuImportProps), /*#__PURE__*/React.createElement(ButtonPermission, {
        permissionList: [{
          code: "".concat(path, ".button.exportMenu"),
          type: 'button',
          meaning: '菜单配置-导出客户化菜单'
        }],
        icon: "export",
        onClick: this.openMenuExportDrawer.bind(this)
      }, intl.get('ciam.menuConfig.view.message.title.exportMenu').d('导出客户化菜单'))), isSiteFlag && /*#__PURE__*/React.createElement(ExcelExport, {
        exportAsync: true,
        requestUrl: "/iam/cpaas/v1/menus/export-site-data",
        queryParams: this.handleGetFormValue()
      })), /*#__PURE__*/React.createElement(Content, null, /*#__PURE__*/React.createElement("div", {
        className: "table-list-search"
      }, /*#__PURE__*/React.createElement(QueryForm, formProps)), /*#__PURE__*/React.createElement(List, listProps)), editorVisible && /*#__PURE__*/React.createElement(Editor, editorProps), /*#__PURE__*/React.createElement(MenuExport, menuExportProps), /*#__PURE__*/React.createElement(PermissionSet, permissionSetProps));
    }
  }]);

  return MenuConfig;
}(React.Component), (_applyDecoratedDescriptor(_class2.prototype, "getRowKeys", [_dec3], Object.getOwnPropertyDescriptor(_class2.prototype, "getRowKeys"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "fetchSearchLabels", [_dec4], Object.getOwnPropertyDescriptor(_class2.prototype, "fetchSearchLabels"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "create", [_dec5], Object.getOwnPropertyDescriptor(_class2.prototype, "create"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "copy", [_dec6], Object.getOwnPropertyDescriptor(_class2.prototype, "copy"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "handleQueryLabel", [_dec7], Object.getOwnPropertyDescriptor(_class2.prototype, "handleQueryLabel"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "fetchCustomMenu", [_dec8], Object.getOwnPropertyDescriptor(_class2.prototype, "fetchCustomMenu"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "handleExportRowSelect", [_dec9], Object.getOwnPropertyDescriptor(_class2.prototype, "handleExportRowSelect"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "handleExport", [_dec10], Object.getOwnPropertyDescriptor(_class2.prototype, "handleExport"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "refreshList", [_dec11], Object.getOwnPropertyDescriptor(_class2.prototype, "refreshList"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "expandClick", [_dec12], Object.getOwnPropertyDescriptor(_class2.prototype, "expandClick"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "handleGetFormValue", [_dec13], Object.getOwnPropertyDescriptor(_class2.prototype, "handleGetFormValue"), _class2.prototype)), _class2)) || _class) || _class);
export { MenuConfig as default };